import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:osg/controllers/http.dart';
import 'package:osg/pages/web_tabs/market/market_list%20copy.dart';

 RxString type= ''.obs;
 RxString jing= ''.obs;
class Synthesis extends StatefulWidget {
   Synthesis({super.key});

  @override
  State<Synthesis> createState() => _SettingPageState();
}

class _SettingPageState extends State<Synthesis> {

  RxList listDate=[].obs;

  getInfo(url){
     Get.find<HTTPS>().getData(url, {'type':jing.value}).then((res){
        if(res!=null){
          listDate.value=res;
        }
      });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
     WidgetsBinding.instance.addPostFrameCallback((_) {
      type.value = Get.parameters['type']!;
      jing.value = Get.parameters['jing']??'1';
      if(type.value=='1'){
        getInfo('/combination');
      }else if(type.value=='2'){
        getInfo('/decompose/index');
      }else{
        getInfo('/exchange/index');
      }

    });
  }

  

  //Text(type==1?'合成活动':type==2?'置换活动':'分解活动')
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
          backgroundColor: Color(0xffffffff),
          title:
          Obx(()=>
          Text(type.value == '1'
              ? jing.value=='2'?'升级活动' :'合成活动'
              : type.value == '2'
                  ? '分解活动'
                  : '置换活动')
          )
           ,
          centerTitle: true),
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 15),
        child: 
        Obx(()=>
        ListView(
          children: [
            if(listDate.isEmpty)
            Container(
      alignment: Alignment.center,
      margin: EdgeInsets.only(top: 100),
      child: Text('暂无数据',
          style: TextStyle(fontSize: 16, color: Color(0XFF999999))),
    )
            ,

            for (var item in listDate.asMap().entries)
              GestureDetector(
                onTap: () => {
                  type.value=='1'?
                  jing.value=='2'?
                  Get.toNamed('/web_tabs/activity/detail?uuid=${item.value['uuid']}&jing=2')
                  :
                  Get.toNamed('/web_tabs/activity/detail?uuid=${item.value['uuid']}')
                 : type.value=='2'?
                  Get.toNamed('/web_tabs/activity/decomposition_detail?uuid=${item.value['uuid']}')
                : Get.toNamed('/web_tabs/activity/replacement_detail?uuid=${item.value['uuid']}')
                },
                child: Column(
                  children: [
                    Stack(
                      children: [
                        // Container(
                        //   height: 320,
                        //   width: ,
                        //   color: Color(0XFF333333),
                        //   child:  ClipRRect(
                        //    borderRadius: BorderRadius.circular(15.0), // 设置圆角大小
                        //    child: Image.network('${item.value['thumb']}',height: 320,fit: BoxFit.fill,),
                        //  ),
                        // ),
                    FractionallySizedBox(
                      widthFactor: 1,
                      child: ClipRRect(
                          borderRadius: BorderRadius.circular(15.0), // 设置圆角大小
                          child: Image.network('${item.value['thumb']}',height: 200,fit: BoxFit.fill,),
                        ),
                    )
                       ,
                        Positioned(
                          bottom: 0,
                          right: 0,
                          left: 0,
                          child: Container(
                            padding: EdgeInsets.symmetric(
                                horizontal: 15, vertical: 10),
                            decoration: BoxDecoration(
                                color: Color(0X83000000),
                                borderRadius: BorderRadius.only(
                                    bottomLeft: Radius.circular(15),
                                    bottomRight: Radius.circular(15))),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(
                                      '${item.value['title']}',
                                      style: TextStyle(
                                          fontSize: 16,
                                          color: Color(0XFFFFFFFF)),
                                    ),
                                    Text(
                                      '限量${item.value['stock']}份',
                                      style: TextStyle(
                                          fontSize: 11,
                                          color: Color(0XFFFFFFFF)),
                                    ),
                                  ],
                                ),
                                Image.asset(
                                  'static/hehe.png',
                                  width: 50,
                                  fit: BoxFit.fitWidth,
                                )
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              '开始时间',
                              style: TextStyle(
                                  fontSize: 11, color: Color(0XFF999999)),
                            ),
                            Text(
                              '${item.value['start_date']}',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color(0XFF0F172B),
                                  fontWeight: FontWeight.bold),
                            )
                          ],
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              '结束时间',
                              style: TextStyle(
                                  fontSize: 11, color: Color(0XFF999999)),
                            ),
                            Text(
                              '${item.value['end_date']}',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color(0XFF0F172B),
                                  fontWeight: FontWeight.bold),
                            )
                          ],
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 20,
                    )
                  ],
                ),
              ),
          ],
        )
        )
        ,
      ),
    );
  }
}
